<template>
  <div :class="['am-slider', 'am-slider-default', 'dg-margin-0', { 'am-slider-carousel' : isNeedCar }]">
    <ul class="am-slides">
      <li v-for="(item, index) in carImgs" :key="index" @click="showCarImg(index)">
        <!-- <router-link v-else :to="'/worksDetail/' + item.id"> -->
        <am-image :src="thumbnail + item.path" v-if="isThumbnail" :responsive="true" />

        <template v-else>
          <a :href="item.path" v-if="item.id < 0" target="_blank">
            <!-- <am-image :src="static_pic +item.path" :responsive="true"/> -->
            <!-- <am-lazy-img :imgsrc="item.path" /> -->
          </a>

          <!-- <router-link v-else :to="'/worksDetail/' + item.id"> -->
            <am-image :src="static_pic + item.path" :responsive="true"  class="dg_car"/>
            <!-- <img v-lazy="static_pic + item.path" class="am-img-responsive" src="" alt=""> -->
          <!-- </router-link> -->
        </template>

      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'carousel',
  data() {
    return {
      ins: ''
    }
  },
  computed: {
    itemWidth() {
      if(this.$store.state.screenWidth < 641) {
        return 120;
      } else {
        return 180;
      }
    }
  },
  props: {
    controlNav: {
      type: [Boolean, String],
      default: true
    },
    carImgIndex: {
      type: Number,
      default: 0
    },
    carImgs: {
      type: Array,
      default() {
        return [{path: '', id: -1}]
      }
    },
    isNeedCar: {// 多图形式
      type: Boolean,
      default: false
    },
    isThumbnail: {
      type: Boolean,
      default: false
    }
  },
  watch: {
    carImgs(val) {
      this.carDown = false;
      this.$nextTick()
      .then(() => {
        this.initCarousel();
      });
    }
  },
  methods: {
    ready() {
      this.initCarousel();
    },

    initCarousel() {
      if(this.carImgs.length > 0) {
        if(this.isNeedCar) {
          $('.am-slider').flexslider({ itemWidth: this.itemWidth, itemMargin: 5, slideshow: false });
        } else {
          $('.am-slider').flexslider({ controlNav: this.controlNav });
        }
      }
    },
    showCarImg(index) {
      this.$emit('update:carImgIndex', index);
    }
  },
  mounted() {
    this.ready();
  }
}
</script>

<style scoped>
@import 'amazeui/dist/css/amazeui.min.css';
</style>